import order from '../../api/order'
import * as orderTypes from './mutation-types'

export const updateAutoOrderInitStatus = ({ commit }, data) => {
  let req = {}
  if (data.autoOrderInitStatus === 'order') {
    req.autoOrderInitStatus = 'busy'
  } else {
    req.autoOrderInitStatus = 'order'
  }
  req._id = data._id
  return new Promise(function (resolve) {
    order
      .updateAutoOrderInitStatus(req)
      .then((response) => {
        if (response.success) {
          const orderReceivorder = {
            autoOrderInitStatus: req.autoOrderInitStatus,
            id: req._id
          }
          commit(orderTypes.SET_ORDER_RECEIVORDER, {orderReceivorder})
          resolve(response)
        }
      })
      .catch((err) => {
        console.log(err)
        // 'message.default_tips'
      })
  })
}
